
//链接网页头部、尾部
$("#header-site").load("/icd/header.html",function(){
    var clientHeight = window.screen.height; //获取屏幕分辨率高度
    var rem = $('html').css("font-size").replace("px","");  //获取html的rem值
    //切换横屏
    var resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize';
    var init = function(){
        if($('html').css("font-size").replace("px","") != rem) {  //rem值发生变化时
            var clientHeight = window.screen.height;
            rem = $('html').css("font-size").replace("px", "");
            $("#nav").css({height: clientHeight / rem -1 + "rem", opacity: 1});
            $("#header-site").css({height:"1rem"});
            var searchChange=false;
            var menuChange=false;
        }
    }
    window.addEventListener(resizeEvt, init, false);


    //打开、关闭菜单导航
    var searchChange=false;
    var menuChange=false;
    //找到dom元素
    var $hdSite = $("#header-site"),$nav = $("#nav"),$searchPanel = $("#searchPanel");

    //关闭显示下拉菜单
    function closeShowPanel(){
        $hdSite.stop(true,false).animate({
            height: '1rem'
        }, 300);
        menuChange=false;
        searchChange=false;
    };



    $(".bar").click(function(e){
        e.stopPropagation();
        if(!menuChange){
            $searchPanel.hide();
            $nav.show();
            $hdSite.stop(true,false).animate({
                height: clientHeight
            }, 300);
            searchChange=false;
            menuChange=!menuChange;
        }else{
            closeShowPanel();
        }
        //导航菜单存在时，为导航绑定点击事件
        if(menuChange){
            $hdSite.click(function(){
                closeShowPanel();
            })
        }
    });
    //打开导航二级菜单
    $("#nav .new ").on("click", function(e){
        e.preventDefault();
        e.stopPropagation();
        $(this).parent().toggleClass("current");
    })
    /*添加搜索按钮事件*/
    $(".showSearchbar").click(function(e){
        e.stopPropagation();
        if(!searchChange){
            $nav.hide();
            $searchPanel.show();
            if(!menuChange){
                $hdSite.animate({
                    height:"2rem"
                }, 300);
            }else{
                $hdSite.css({
                    height:"2rem"
                });
            }
            searchChange=!searchChange;
            menuChange=false;
        }else{
            closeShowPanel();
        }
        if(searchChange){
            $hdSite.click(function(){
                closeShowPanel();
            })
        }
    });

    $("#searchPanel").on("click",function(e){
        e.stopPropagation();
    });
    $(document).on("click",function(){
        closeShowPanel();
    });

});
$("#footer-site").load("/icd/footer.html",function(){
    $(".Microblocbox").on("click",function(){

        var url = $(this).attr('data-url');
        if(url){
            location.href = url;
        }
    })
});


//视频播放控制
//1、点击播放，遮罩消失，视频播放
$(".shipin").on("click",".indexPlayIcon img",function(){
    $(".mask").addClass("hdn").prev()[0].play();
});
//2、暂停播放，遮罩显示，视频暂停
/*$(".shipin video")[0].onpause=function(){
 $(".shipin .mask").removeClass("hdn").prev()[0].pause();
 };*/
//3、重新播放
/*
if($(".shipin video ")[0].ended){

}
*/


//返回顶部
$("#toTop a").click(function(e){
    e.preventDefault();
    document.documentElement.scrollTop = document.body.scrollTop = 0;
})